package com.qiangesoft.blog.controller.manage;

import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.core.entity.BlogSource;
import com.qiangesoft.blog.core.pojo.query.SourceQueryDTO;
import com.qiangesoft.blog.core.pojo.vo.ArticleListVO;
import com.qiangesoft.blog.core.service.IBlogSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 源码管理 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/source")
@RequiredArgsConstructor
@Api(tags = "源码管理")
public class BlogSourceController {

    private final IBlogSourceService sourceService;

    @GetMapping(value = "/list")
    @ApiOperation(value = "文章列表")
    public PageResultVO<BlogSource> list(@Validated PageQuery pageQuery, SourceQueryDTO sourceQuery) {
        return sourceService.pageSource(pageQuery, sourceQuery);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value = "文章详情")
    public BlogSource getArticleById(Long id) {
        return sourceService.getSourceById(id);
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "保存文章")
    @OperationLog(value = "保存文章")
    public void insert(@RequestBody BlogSource source) {
        sourceService.insertSource(source);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改文章")
    @OperationLog(value = "修改文章")
    public void update(@RequestBody BlogSource source) {
        sourceService.updateSource(source);
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation(value = "删除文章")
    @OperationLog(value = "删除文章")
    public void delete(Long id) {
        sourceService.deleteSource(id);
    }

    @DeleteMapping(value = "/deleteBatch")
    @ApiOperation(value = "批量删除文章")
    @OperationLog(value = "批量删除文章")
    public void deleteBatch(@RequestBody List<Long> ids) {
        sourceService.deleteBatchSource(ids);
    }

    @PostMapping(value = "/top")
    @ApiOperation(value = "置顶文章")
    @OperationLog(value = "置顶文章")
    public void putTopSource(@RequestBody BlogSource source) {
        sourceService.putTopSource(source);
    }

    @PostMapping(value = "/publish")
    @ApiOperation(value = "发布或下架文章")
    @OperationLog(value = "发布或下架文章")
    public void publish(@RequestBody BlogSource source) {
        sourceService.publishAndShelf(source);
    }

}
